package bgg4j;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class WishGame extends Game {

	WishGame(Element elem, Bgg bgg) throws BggException {
		super(elem, bgg);
		// TODO 自動生成されたコンストラクター・スタブ
	}
	
	public int getGameID(){
		return Integer.valueOf(this.getAttributeText("objectid"));
	}
	
	public String getName(){
		return this.getChildText("name");
	}
	
	public String getOrgName(){
		return this.getChildText("originalname");
	}
	
	public String getThumbnail(){
		return this.getChildText("thumbnail");
	}
	
	public double getRating(){
		double ret=0;
		if (!this.getChildAttribute("stats","rating").equals("")){
			ret = Double.valueOf(this.getChildAttribute("stats","rating"));
		}
		return ret;
	}
	
	public float getBggrating(){
		float ret = 0;
		if (!this.getChildAttribute("stats","bggrating").equals("")){
			ret = Float.valueOf(this.getChildAttribute("stats","bggrating"));
		}
		return ret;
	}
	
	public int getRank(){
		int ret = -1;
		if (!this.getChildAttribute("stats","rank").equals("")){
			ret = Integer.valueOf(this.getChildAttribute("stats","rank"));
		}
		return ret;
	}
	
	public int getNumPlays(){
		int ret = 0;
		if (!this.getChildText("numplays").equals("")){
			ret = Integer.valueOf(this.getChildText("numplays"));
		}
		return ret;
	}
	
	public 
    /*package*/ static List<WishGame> constructWishGames(Document doc,
            Bgg bgg) throws BggException{
            if (null == doc) {
                return new ArrayList<WishGame> (0);
            } else {
                try {
                    ensureRootNodeNameIs("items", doc.getDocumentElement());
                    NodeList list = doc.getDocumentElement().getElementsByTagName(
                            "item");
                    int size = list.getLength();
                    List<WishGame> statuses = new ArrayList<WishGame>(size);
                    for (int i = 0; i < size; i++) {
                        Element status = (Element) list.item(i);
                        statuses.add(new WishGame(status, bgg));
                    }
                    return statuses;
                } catch (BggException te) {
                    return new ArrayList<WishGame>(0);
                }
            }
        }
}
